﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 实验1._1_Calc
{
    public partial class Calc : Form
    {
        static private Calculate calc = new CalculateImpl();

        public Calc()
        {
            InitializeComponent();
        }

        private void btn_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            this.tb_in.Text += btn.Text;
            btn_result_Click(sender, e);
        }

        private void btn_result_Click(object sender, EventArgs e)
        {
            // 获取输入框的文本
            String str = this.tb_in.Text;
            // 调用Calculator类对象进行计算
            string result = calc.calculate(str);
            // 输出框输出结果
            this.tb_out.Text = "= " + result;
        }

        private void btn_AC_Click(object sender, EventArgs e)
        {
            this.tb_in.Text = "";
            this.tb_out.Text = "= 0";
        }

        private void btn_del_Click(object sender, EventArgs e)
        {
            // 获取输入框的文本
            string str = this.tb_in.Text;
            if (str.Length > 0)
            {
                string newstr = str.Remove(str.Length - 1);
                this.tb_in.Text = newstr;
            }
            btn_result_Click(sender, e);
        }
    }
}
